<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单数据</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
        <el-row>
            <el-col :span="8">
                <el-input placeholder="请输入内容">
                    <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
            </el-col>
            <el-table :data="orderlist" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"></el-table-column>
                <el-table-column label="是否付款">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.pay_status === 1" type="success">已付款</el-tag>
                        <el-tag v-else type="danger">未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货"></el-table-column>
                <el-table-column label="下单时间">
                    <template slot-scope="scope">
                        {{scope.row.create_time | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="220">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="edit(scope.row)">修改地址</el-button>
                        <el-button type="success" icon="el-icon-location" size="mini" @click="progress(scope.row)">物流</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagesize"
            :page-sizes="[10,20,50,100]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            ></el-pagination>
        </el-row>
    </el-card>
    <Address :show.sync="showAddress"></Address>
    <Progress :show.sync="showProgress"></Progress>
  </div>
</template>

<script>
import Address from './Address'
import Progress from './Progress'
export default {
  name: 'Order',
  components: {
    Address,
    Progress
  },
  data() {
    return {
      queryInfo: {
        query: '',
        pagesize: 10,
        pagenum: 1
      },
      total: 0,
      orderlist: [],
      showAddress: false,
      showProgress: false
    }
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      this.$message.success(res.meta.msg)
      console.log(res.data)
      this.total = res.data.total
      this.orderlist = res.data.goods
    },
    handleSizeChange(newPagesize) {
      this.queryInfo.pagesize = newPagesize
      this.getOrderList()
    },
    handleCurrentChange(newPagenum) {
      this.queryInfo.pagenum = newPagenum
      this.getOrderList()
    },
    edit() {
      this.showAddress = true
    },
    progress() {
      this.showProgress = true
    }
  },
  created() {
    this.getOrderList()
  }
}
</script>

<style lang="less" scoped></style>
